# 分形树
import turtle


def fractalTree(size, angle, var, border):
    if size >= border:
        turtle.fd(size)
        # 画右边树
        turtle.right(angle)
        fractalTree(size - var, angle, var, border)
        # 画左边树
        turtle.left(angle * 2)
        fractalTree(size - var, angle, var, border)
        # 后退
        turtle.right(angle)
        turtle.backward(size)


def main():
    turtle.title("分形树")
    width = 900
    height = 600
    startX = 200
    startY = 100
    turtle.setup(width, height, startX, startY)
    turtle.pensize(1)
    turtle.tracer(2)
    turtle.hideturtle()
    turtle.bgcolor("#000")
    turtle.pencolor("#fff")
    turtle.penup()
    turtle.goto(-50, -250)
    turtle.pendown()
    turtle.left(90)
    fractalTree(100, 20, 10, 5)
    turtle.done()


main()
